<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
</head>
<body>

<form action="" method="post">
    用户名：<input name="userName">&nbsp;&nbsp;
    <input type="submit" name="submit" value="登录">
</form>
<a href="regist.jsp">注册用户</a>
<%
    String submit=request.getParameter("submit");
    if(submit==""||submit==null){
        return;
    }else{
        String name=request.getParameter("userName");
        List<String> users=(List<String>) application.getAttribute("users");
        if(users==null||users.size()==0){
            response.sendRedirect("error.jsp");
            return;
        }
        boolean flag=false;
        for(String user:users){
            if(user.equals(name)) {
                flag=true;
                break;
            }
        }
        if(flag){
            session.setAttribute("user",name);
            if(name.equals("admin"))
                request.getRequestDispatcher("admin.jsp")
                        .forward(request,response);
            else
                response.sendRedirect("test.jsp");
        }else
            response.sendRedirect("error.jsp");
    }


%>
</body>
</html>
